package coroutines

import kotlinx.coroutines.*
import org.springframework.util.StopWatch

suspend fun searchOne(): String {
    delay(1000L)
    return "search one"
}

suspend fun searchTwo(): String {
    delay(2000L)
    return "search two"
}

suspend fun main() {
    val stopWatch = StopWatch("async-await")
    stopWatch.start()
    val job = CoroutineScope(context = Dispatchers.Default).launch {
        val one = async { searchOne() }
        val two = async { searchTwo() }
        println("The item is ${one.await()} and ${two.await()}")
    }
    job.join()
    stopWatch.stop()
    println(stopWatch.prettyPrint())
}